package com.student.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.student.dao.CourseDao;
import com.student.model.Course;
import com.student.model.*;

@WebServlet("/ShowChooseCoursePageServlet")
public class ShowChooseCoursePageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public ShowChooseCoursePageServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		CourseDao cd = new CourseDao();
		HttpSession session = request.getSession();
		User info = (User) session.getAttribute("info");
		
		String studentName = info.getUsername();
		List<Course> AllowSelectionCourseList;
		
		try {
			AllowSelectionCourseList = (List<Course>) cd.getAllowSelectionCourseList(new String[] {studentName});
			request.setAttribute("AllowSelectionCourseList", AllowSelectionCourseList);
			session.setAttribute("AllowSelectionCourseList", AllowSelectionCourseList);
			request.getRequestDispatcher("/view/student/chooseCourse.jsp").forward(request, response);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		

	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
